<template>
    <div class="app-container editcss">
        <el-row :gutter="0" class="el-card is-always-shadow el-card__body  card_contents" style="padding: 0px;">
            <el-col class="titleHeight">
                <el-row class="content_h">
                    <el-col class="title_tops">
                        <div class="title_tops_t">
                            <div class="title_top_E">Time Order Settlement</div>
                            <div class="title_top_C">时间订单结算</div>
                        </div>
                    </el-col>
                    <el-col class="screen_case">
                        <el-row>
                            <el-col :span="4">
                                <div class="screen_case_amount mb20">
                                    <span class="screen_case_amount_lable">调拨订单数量：</span>
                                    <span class="screen_case_amount_value">{{total}}</span>
                                </div>
                                <div style="display: flex;align-items: center;">
                                    <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll"
                                    @change="handleCheckAllChange" class="checkAllCL">全选</el-checkbox>
                                <el-button type="primary" class="ch_button" @click="settleaccounts">
                                    <img class="ch_button_img" src="../../assets/iconfont/jiesuan.png" alt="" srcset="">
                                    <div>结算</div>
                                </el-button>
                                </div>
                            </el-col>
                            <el-col :span="5">
                                <screenSelect title="机构名称" type='input' v-model="queryFrom.hospitalName" :isValue='queryFrom.hospitalName'
                                    placeholder="请输入" @transfer="valueHeld($event, 'hospitalName')" class="mb15" />
                                <screenSelect title="时间订单ID" type='input' v-model="queryFrom.timTransferNo"
                                    :isValue='queryFrom.timTransferNo' placeholder="请输入"
                                    @transfer="valueHeld($event, 'timTransferNo')" class="" />
                            </el-col>
                            <el-col :span="5">
                                <screenSelect title="结算状态" type='select' v-model="queryFrom.settlementStatus"
                                            :isValue='queryFrom.settlementStatus' placeholder="请选择"
                                            @transfer="valueHeld($event, 'settlementStatus')"
                                            :options="isSettlementStatusoptions" class=" mb15" />
                                            <screenSelect title="调拨类型" type='select' v-model="queryFrom.transferType"
                                :isValue='queryFrom.transferType' placeholder="请选择"
                                @transfer="valueHeld($event, 'transferType')" :options="transferTypeoptions" class="" />
                            </el-col>
                            <el-col :span="10">
                                <screenSelect title="时间段筛选" type='daterange' v-model="queryFrom.transferDateTime"
                                        :isValue='queryFrom.transferDateTime'
                                        @transfer="valueHeld($event, 'transferDateTime')" width='343px' class=" mb15"/>
                                <el-button type="primary" class="ch_button " @click="search">
                                    <img class="ch_button_img" src="../../assets/iconfont/zoom-out.png" alt="" srcset="">
                                    <div>搜索</div>
                                </el-button>
                                <el-button type="primary" class="ch_button " @click="reset">
                                    <img class="ch_button_img" src="../../assets/iconfont/rotate-ccw.png" alt="" srcset="">
                                    <div>选项重置</div>
                                </el-button>
                                <el-button type="primary" class="ch_button " :disabled="isDerive" @click="derive">
                                    <img class="ch_button_img" src="../../assets/iconfont/share.png" alt="" srcset="">
                                    <div>数据导出</div>
                                </el-button>
                            </el-col>
                        </el-row>
                    </el-col>

                </el-row>
            </el-col>
            <el-col class="dialog_title_ch_conter_operate  card_contents_tex">
                <el-table border  :key="randomTableKey" :height="endHeight" ref="multipleTable" @selection-change="handleSelectionChange" :data="tableData" fit
                    style="width: 100%;" header-row-class-name="hrcn" row-class-name="rcn">
                    <el-table-column align="center" type="selection" width="54">
                    </el-table-column>
                    <el-table-column align="center" label="ID" min-width="200">
                        <template slot-scope="scope">
                            {{ scope.row.timTransferNo }}
                        </template>
                    </el-table-column>
                    <el-table-column align="center" label="接收机构名称" min-width="250">
                        <template slot-scope="scope">
                            {{ scope.row.hospitalName }}
                        </template>
                    </el-table-column>
                    <el-table-column align="center" label="调拨类型" min-width="97">
                        <template slot-scope="scope">
                            {{ transferTypeoptionsA[scope.row.transferType] }}
                        </template>
                    </el-table-column>
                    <el-table-column align="center" label="调拨数量" min-width="97">
                        <template slot-scope="scope">
                            {{ scope.row.transferNumber }}
                        </template>
                    </el-table-column>
                    <el-table-column align="center" label="调拨时间" min-width="129">
                        <template slot-scope="scope">
                            {{ parseTime(scope.row.transferDate,'{y}.{m}.{d}') }}
                        </template>
                    </el-table-column>
                    <el-table-column align="center" label="结算状态" min-width="100">
                        <template slot-scope="scope">
                            <div :style="scope.row.settlementStatus == 1 ? 'color:#19CDA6;' : 'color:#FE294D;'">
                                {{ isSettlementStatusoptionsA[scope.row.settlementStatus] }}
                            </div>

                        </template>
                    </el-table-column>
                    <el-table-column align="center" label="结算操作人" min-width="113">
                        <template slot-scope="scope">
                            {{ scope.row.settlementName }}
                        </template>
                    </el-table-column>
                    <el-table-column align="center" label="结算时间" min-width="199">
                        <template slot-scope="scope">
                            {{ parseTime(scope.row.settlementDate, '{y}-{m}-{d} {h}:{i}:{s}') }}
                        </template>
                    </el-table-column>
					<el-table-column fixed="right" align="center" label="" width="1">
					  </el-table-column>
                </el-table>
                <div class="paginationblock" v-if="total > 0">
                    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                        :current-page="pageData.pageNo" :page-sizes="[10, 20, 30, 40]" :page-size="pageData.pageSize"
                        :background="true" layout="total, sizes, prev, pager, next, jumper" :total="total">
                    </el-pagination>
                </div>
            </el-col>
        </el-row>

        <!-- 结算 -->
        <el-dialog title="提示" :visible.sync="jbDialogVisible" custom-class="settleDialog" :show-close='false' :modal='true'>
            <span class="deleteDialogSpanconter">您确认要结算此订单吗？</span>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="confirmHeld">确认结算</el-button>
                <el-button type="primary" @click="jbDialogVisible = false">取消</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import construction from '@/components/construction/index.vue'
import screenSelect from '@/components/screenSelect/index.vue'
import steplog from '@/components/steplog/index.vue'
import { getTimePageList } from '@/api/timeallot'
import { getProvince, getCity, getArea } from '@/api/common'
import { formatDates } from '@/utils/index'
import { getTimeSettlement ,getTimeExpor} from '@/api/settlement'
import {
    mapGetters
} from 'vuex'
export default {
    name: "equipmentindex",
    components: {
        construction,
        screenSelect,
        steplog
    },
    computed: {
        ...mapGetters([
            'timeordersettlement'
        ])
    },
    data() {
        return {
            delDialogVisible: false,
            addDialogVisible: false,
            rentDialogVisible: false,
            jbDialogVisible: false,
            institutionName: '',
            provinceName: '',
            fromDatas: {

            },
            isSettlementStatusoptionsA: ['未结算', '已结算'],
            isSettlementStatusoptions: [
                {
                    value: 0,
                    label: '未结算'
                },
                {
                    value: 1,
                    label: '已结算'
                },
            ],
            options: [{
                value: 'Chengdu',
                label: '成都'
            }, {
                value: 'Shenzhen',
                label: '深圳'
            }, {
                value: 'Guangzhou',
                label: '广州'
            }, {
                value: 'Dalian',
                label: '大连'
            }],
            tableData: [],
            multipleSelection: [],
            idSlit: [],
            checkAll: false,
            isIndeterminate: false,
            queryFrom: {
                settlementStatus:'',
                transferType: '',
                auditStatus: '',
                hospitalName: '',
                transferDateTime: '',
                transferDateStart: '',
                transferDateEnd: ''
            },
            transferTypeoptionsA:['小时','天'],
            transferTypeoptions:[
              {
                label:'小时',
                value:0
              },
              {
                label:'天',
                value:1
              }
            ],
            pageData: {
                pageNo: 1,
                pageSize: 10
            },
            total: 0,
            endHeight:0,
            randomTableKey:null,
			isDerive:false
        };
    },
    mounted() {
        console.log(this.$route);
        this.getList()
        let fHeight = (window.getComputedStyle(document.querySelector('.editcss')).height).replace('px', "")
        let zHeight = (window.getComputedStyle(document.querySelector('.titleHeight')).height).replace('px', "")
        this.endHeight = (fHeight-zHeight-120)
    },
    methods: {
        getList() {
            let that = this
            const loading = that.$loading({
                lock: true,
                text: 'Loading...',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
            });
            getTimePageList(this.queryFrom, this.pageData).then(res => {
                if (res.code == 200) {
                    this.tableData = res.data.dbTimeTransferPage.records
                    this.total = res.data.dbTimeTransferPage.total
                    this.randomTableKey = Math.random()
                    loading.close()
                }
            })
        },
        handleSizeChange(val) {
            this.pageData.pageSize = val
            this.getList()
        },
        handleCurrentChange(val) {
            this.pageData.pageNo = val
            this.getList()
        },
        valueHeld(childParam, fatherparam) {
            this.queryFrom[fatherparam] = childParam
        },
        search() {
            this.pageData={
					pageNo: 1,
					pageSize: 10
				}
            if (this.queryFrom.transferDateTime != '') {
                this.queryFrom.transferDateEnd = formatDates(this.queryFrom.transferDateTime[1])
                this.queryFrom.transferDateStart = formatDates(this.queryFrom.transferDateTime[0])
            }
            this.getList()
        },
        reset() {
            this.queryFrom = {
                settlementStatus:'',
                transferType: '',
                auditStatus: '',
                hospitalName: '',
                transferDateTime: '',
                transferDateStart: '',
                transferDateEnd: ''
            }
            this.getList()
        },
        derive() {
            this.isDerive = true
			if (this.queryFrom.transferDateTime != '') {
			    this.queryFrom.transferDateEnd = formatDates(this.queryFrom.transferDateTime[1])
			    this.queryFrom.transferDateStart = formatDates(this.queryFrom.transferDateTime[0])
			}
			if(this.queryFrom.transferDateTime=='' || this.queryFrom.transferDateStart==''){
				this.$Toast('请先选择时间再导出')
				this.isDerive = false
				return
			}
			getTimeExpor(this.queryFrom).then(res => {
			  const link = document.createElement('a')
			  const blob = new Blob([res.data], {
			    type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
			  })
			  console.log(res);
			  const fileName = decodeURI(res.headers['content-disposition'].split(';')[1].split('=')[1].substring(7));
			  link.setAttribute('download',fileName)
			  link.style.display = 'none'
			  link.href = URL.createObjectURL(blob)
			  link.click()
			  setTimeout(()=>{
			  	this.isDerive = false
			  },5000)
			}).catch(err=>{
				setTimeout(()=>{
					this.isDerive = false
				},5000)
			})
        },
        // delClick(row) {
        //     this.delDialogVisible = true
        //     console.log(row);
        // },
        // 确认结算
        confirmHeld() {
            let newData = {}
            newData.ids = this.idSlit
            console.log(newData);
            getTimeSettlement(newData).then(res => {
                if (res.code == 200) {
                    this.jbDialogVisible = false
                    this.$Toast('结算成功')
                    this.multipleSelection = []
                    this.checkAll = false
                    this.isIndeterminate = false
                    this.$refs.multipleTable.clearSelection()
                    this.getList()
                }
            })
        },
        //结算
        settleaccounts() {
            this.idSlit = []
            if (this.multipleSelection.length > 0) {
                this.multipleSelection.map(item => {
                    this.idSlit.push(item.timeTransferId)
                })
                this.jbDialogVisible = true
            } else {
                this.$Toast('请勾选需要结算的订单')
            }
        },
        handleCheckAllChange(val) {
            this.isIndeterminate = false
            this.checkAll = val
            if (val) {
                this.$refs.multipleTable.clearSelection()
                this.tableData.map(item => {
                    this.$refs.multipleTable.toggleRowSelection(item)
                })
            } else {
                this.$refs.multipleTable.clearSelection()
            }
        },
        handleSelectionChange(val) {
            this.multipleSelection = val;
            if (val.length > 0) {
                if (val.length == this.tableData.length) {
                    this.isIndeterminate = false
                    this.checkAll = true
                } else {
                    this.isIndeterminate = true
                    this.checkAll = false
                }
            } else if (val.length == 0) {
                this.isIndeterminate = false
                this.checkAll = false
            }
        },
        // 提交
    }
}
</script>

<style lang="scss" scoped>
.editcss {
    overflow-y: auto;
}

::v-deep .hrcn th {
    background-color: #FFFFFF;
    color: #989898;
    font-size: 15px;
    font-weight: 400;
}

::v-deep .hrcn th:nth-child(1) .el-checkbox {
    visibility: hidden;
}

::v-deep .el-table__fixed-right {
    height: calc(100% - 10px) !important;
}

::v-deep .el-table__fixed-right::before {
    display: none;
}

::v-deep .hrcn th .cell {
    border-right: 1px solid #EFEFEF;

}

::v-deep .hrcn th:last-child .cell {
    border-right: none;
}

::v-deep .rcn {
    color: #000;
    font-size: 16px;
    font-weight: 400;
}

.card_contents {
    height: calc(100% - 1px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    // justify-content: center;

    .card_contents_tex {
        flex: 1;
        overflow-y: auto;
        margin-bottom: 20px;
        // padding: 20px;
        min-height: 200px;
    }

    .card_contents_footer {
        padding: 16px 0;
        display: flex;
        align-items: center;
        justify-content: center;
        border-top: 1px solid #EFEFEF;
    }
}

.content_h {
    min-height: 149px;
    border-radius: 5px;
    padding: 0px;
    border-bottom: 1px solid #EFEFEF;
    padding-bottom: 14px;
}

.title_tops {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0 20px;
    min-height: 79px;
    border-bottom: 1px solid #EFEFEF;

    .title_tops_t {
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
}

.screen_case_title {
    font-size: 16px;
    font-weight: 400;
    color: #000;
    margin-right: 35px;
}

.title_top_E {
    font-size: 12px;
    font-weight: 400;
    color: #9898989E;
}

.title_top_C {
    font-size: 18px;
    font-weight: 400;
    color: #000;
}

.screen_case {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    padding: 14px 20px 0;
}

.screen_case_amount {
    // margin-right: 38px;
    min-width: 210px;

    .screen_case_amount_lable {
        font-size: 15px;
        color: #989898;
    }

    .screen_case_amount_value {
        font-size: 16px;
        color: #000;
    }
}

::v-deep .ch_button_seav {
    padding: 7px 27px;

    span {
        display: flex;
        align-items: center;
        justify-content: center;

        div {
            font-size: 16px;
            font-weight: 400;
            margin-left: 10px;
        }
    }
}

.ch_button_img_seav {
    width: 24px;
    height: 24px;
}

.dialog_title_ch_conter_operate {
    // padding: 24px 35px;
    // border: 1px solid #EBEBEB;
    border-radius: 2px;
    // display: flex;
    // align-items: center;
}

::v-deep .editbtn span,
::v-deep .jiebangbtn span,
::v-deep .delbtn span {
    display: flex;
    align-items: center;
    justify-content: center;
}

.editbtn,
.jiebangbtn,
.delbtn {
    img {
        width: 15px;
        height: 15px;
        margin-right: 4px;
    }
}

.delbtn {
    color: #FE294D;
    // margin-left: 57px;
}

.jiebangbtnav {
    color: #989898;
}

.editbtn:active,
.jiebangbtn:active,
.delbtn:active {
    opacity: .6;
}

.el-dialog__wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
}

//新增弹窗
::v-deep .addeteDialog {
    background-color: #FFFFFF;
    width: 1268px;
    // height: 764px;
    border-radius: 6px;
    box-shadow: 0 0 10px #60778E47;
    display: flex;
    flex-direction: column;
}

::v-deep .addeteDialog .el-dialog__header {
    height: 80px;

    div {
        display: flex;
        flex-direction: column;
    }

    border-bottom: 1px solid #EFEFEF;

    // 自定义弹窗x号
    .el-dialog__close::before {
        content: ' ';
        background: url(../../assets/iconfont/x-circle.png);
        background-size: 20px 20px;
        width: 20px;
        height: 20px;
        display: flex;
    }

    .el-dialog__close:active::before {
        background: url(../../assets/iconfont/x-circleactive.png);
        background-size: 20px 20px;
    }
}

::v-deep .addeteDialog .el-dialog__body {
    padding: 17px 20px;

    .addeteDialog_conter {
        // border: 1px solid #EFEFEF;
        flex: auto;
        display: flex;
        flex-direction: column;

        .top_content {
            flex: 1;
            min-height: 200px;
            max-height: 580px;
            overflow-y: auto;

            // padding: 20px 23px;
            .top_content_item {
                border: 1px solid #EFEFEF;
                padding: 11px 17px;
                margin-bottom: 14px;
                display: flex;
                align-items: center;
                justify-content: space-between;

                img {
                    width: 106px;
                    height: 106px;
                }

                .top_content_item_foot {
                    .top_content_item_footT {
                        font-size: 12px;
                        color: #989898;
                    }

                    .top_content_item_footT span:nth-child(1) {
                        font-size: 32px;
                        color: #000;
                    }

                    .top_content_item_footB {
                        display: flex;
                        flex-direction: column;
                        align-items: center;
                        font-size: 12px;
                        color: #989898;
                    }

                    .top_content_item_footB span:nth-child(2) {
                        font-size: 32px;
                        color: #000;
                    }
                }

            }

            .content_checkbox {
                .title_che {
                    margin-top: 20px;
                    margin-bottom: 10px;
                    font-size: 15px;
                    font-weight: 400;
                    color: #989898;
                }

                .title_che_sup {
                    font-size: 13px;
                    font-weight: 400;
                    color: #414141;
                }

                .el-checkbox {
                    margin-top: 8px;
                }

            }
        }

        .footer_submit {
            display: flex;
            align-items: center;
            justify-content: center;
            border-top: 1px solid #EFEFEF;
            padding: 10px 0 15px 0;
        }
    }
}


//弹窗
::v-deep .settleDialog {
    background-color: #FFFFFF;
    width: 552px;
    height: 332px;
    border-radius: 6px;
    box-shadow: 0 0 10px #60778E47;
    display: flex;
    flex-direction: column;
}

::v-deep .settleDialog .el-dialog__header {
    .el-dialog__title {
        color: #000;
        font-size: 18px;
        font-weight: 400;
    }

    border-bottom: 1px solid #EFEFEF;
}

::v-deep .deleteDialogSpanconter {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    font-size: 18px;
    font-weight: 400;
    color: #000;
}

::v-deep .settleDialog .el-dialog__body {
    flex: 1;
}

.settleDialog .dialog-footer {
    display: flex;
    justify-content: center;
    align-items: center;

    button {
        width: 120px;
        height: 38px;
        border-radius: 1px;
        font-size: 16px;
        font-weight: 400;
        color: #FFFFFF;
    }

    button:active {
        opacity: .6;
    }

    button:nth-child(1) {
        margin-right: 32px;
    }

    button {
        background-color: #0584FE;
        border-color: #0584FE;
    }
}

::v-deep .el-button.ch_button {
    padding: 8px 9px;
}

::v-deep .el-button.ch_button span {
    display: flex;
    align-items: center;

    div {
        font-size: 13px;
        font-weight: 400;
        margin-left: 4px;
    }
}

.authority {
    margin-bottom: 25px;
}

.checkAllCL {
    margin-right: 28px;
}
::v-deep .el-table--border td{
  border-right: 0;
}
::v-deep .el-table--border th{
  border-right: 0;
}
::v-deep .el-table__body tr.hover-row.current-row>td,::v-deep .el-table__body tr.hover-row.el-table__row--striped.current-row>td,::v-deep .el-table__body tr.hover-row.el-table__row--striped>td,::v-deep .el-table__body tr.hover-row>td{
     background-color:#dbdbdb;
 }
</style>
